﻿using NicoView.Model.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NicoView.ViewModel
{
    /// <summary>
    /// ニコニコサービス表示モデル
    /// </summary>
    public class NicoViewServiceViewModel:NicoViewViewModelBase
    {

        public NicoViewServiceViewModel()
        {
            this.InternalApplication.Instance.PropertyChanged += this.OnPropertyChanged;
        }

        internal INicoService CurrentService
        {
            get
            {
                return this.InternalApplication.Instance.CurrentService;
            }
        }

        /// <summary>
        /// サービスの経過時間
        /// </summary>
        public TimeSpan ServiceElapsedTime
        {
            get
            {
                if (this.CurrentService == null)
                {
                    return default(TimeSpan);
                }


                return this.CurrentService.ServiceElapsedTime;
            }

            set
            {
                if (this.CurrentService != null)
                {
                    this.CurrentService.ServiceElapsedTime = value;
                }
            }
        }

        /// <summary>
        /// アクティブ人数
        /// </summary>
        public int ActiveWatchCount
        {
            get
            {
                if (this.CurrentService == null)
                {
                    return default(int);
                }
                return this.CurrentService.ActiveWatchCount;
            }
        }

        /// <summary>
        /// 視聴者数
        /// </summary>
        public int WatchCount
        {
            get
            {
                if (this.CurrentService == null)
                {
                    return default(int);
                }
                return this.CurrentService.WatchCount;
            }
        }

        /// <summary>
        /// コメント数
        /// </summary>
        public int CommentCount
        {
            get
            {
                if (this.CurrentService == null)
                {
                    return default(int);
                }
                return this.CurrentService.CommentCount;
            }
        }

        protected override void OnPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (this.CurrentService != null)
            {
                this.CurrentService.PropertyChanged += base.OnPropertyChanged;
            }
            
            base.OnPropertyChanged(sender, e);
        }
    }
}
